package com.wigem.approve.controller;

import com.wigem.framework.common.pojo.PageResult;
import com.wigem.framework.common.util.web.response.Result;
import com.wigem.framework.common.util.web.response.ResultController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wigem.approve.entity.DicReportEntity;
import com.wigem.approve.service.DicReportService;
import com.wigem.approve.vo.DicReportVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.text.html.parser.Entity;

/**
 * 报告期字典Controller
 *
 * @author DH
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/approve/report")
public class DicReportController extends ResultController {


    @Resource
    private DicReportService dicReportService;

    /**
     * 查询报告期字典列表
     */
    @ResponseBody
    @GetMapping("/query")
    public Result getList(DicReportVo dicReportVo) {
        return success(dicReportService.getList(dicReportVo));
    }

    /**
     * 查询报告期字典列表
     */
    @ResponseBody
    @GetMapping("/query/page")
    public Result getPageList(DicReportVo dicReportVo) {
        PageResult<DicReportEntity> pageInfo = dicReportService.getPageList(dicReportVo);
        return success(pageInfo);
    }

    /**
     * 查询报告期字典实体
     */
    @ResponseBody
    @GetMapping("/query/{id}")
    public Result getEntity(@PathVariable("id") String id) {
        return success(dicReportService.getEntity(id));
    }

    /**
     * 查询当前最新报告期
     */
    @ResponseBody
    @GetMapping("/query/current/reportId")
    public Result getCurrentReportId(String stageId) {
        return success(dicReportService.getCurrentReportId(stageId));
    }

    /**
     * 一次把不同阶段报告期查询出来
     * @return
     */
    @GetMapping("/query/allStageReports")
    public Result getAllStageReports() {
        Map<String, DicReportEntity> map = new HashMap<>();
        map.put("stage1Report", dicReportService.getCurrentReportId("1"));
        map.put("stage2Report", dicReportService.getCurrentReportId("2"));
        map.put("stage3Report", dicReportService.getCurrentReportId("3"));
        return Result.success(map);
    }
    /**
     * 报告期字典新增
     */
    @ResponseBody
    @PostMapping
    public Result add(@RequestBody DicReportVo dicReportVo) {
        dicReportService.add(dicReportVo);
        return success("保存成功");
    }

    /**
     * 报告期字典修改
     */
    @ResponseBody
    @PutMapping
    public Result update(@RequestBody DicReportVo dicReportVo) {
        dicReportService.update(dicReportVo);
        return success("修改成功");
    }


    /**
     * 新增保存
     */
    @ResponseBody
    @PostMapping("/save")
    public Result save(@RequestBody DicReportVo dicReportVo) {
        dicReportService.save(dicReportVo);
        return success("保存成功！");
    }


    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id) {
        dicReportService.delete(id);
        return success("删除成功！");
    }

    /**
     * 移除/逻辑删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") String id) {
        dicReportService.remove(id);
        return success("删除成功！");
    }
}
